package com.dotools.privacy;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.dotools.procommon.R;
import com.dotools.umlibrary.UMPostUtils;

import java.util.HashMap;
import java.util.Map;

public class FeedBackActivity extends Activity {

    private ImageView mBack;
    private TextView sub;
    private EditText edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        mBack = findViewById(R.id.ido_feed_back);
        sub = findViewById(R.id.feedback_sub);
        edit = findViewById(R.id.feedback_edit);
        edit.postDelayed(new Runnable() {
            @Override
            public void run() {
                edit.requestFocus();
                InputMethodManager manager = ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE));
                if (manager != null) manager.showSoftInput(edit, 0);
            }
        }, 200);
        mBack .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str=edit.getText().toString();
                str=str.replace(" ", "");
                if (!str.equals("")) {
                    sub.setEnabled(false);
                    Map<String, String> map = new HashMap<>();
                    map.put("feedback", String.valueOf(edit.getText()));
                    UMPostUtils.INSTANCE.onEventMap(getApplicationContext(), "feedback", map);
                    Toast.makeText(FeedBackActivity.this, "感谢反馈", Toast.LENGTH_SHORT).show();
                    finish();
                } else {
                    Toast.makeText(FeedBackActivity.this, "请填写意见", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        UMPostUtils.INSTANCE.onActivityResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        UMPostUtils.INSTANCE.onActivityPause(this);
        try {
            InputMethodManager manager = ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE));
            if (manager != null)
                manager.hideSoftInputFromWindow(edit.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
        }catch (Exception e){

        }
    }




}
